<?php

namespace App\Models\Tag;


class TagFinder
{
    public static function extractTags($content, $top_k = 20)
    {
        $data = ['text' => $content, 'limit' => $top_k];
        $data = http_build_query($data);
        $opts = [
            'http'=>[
                'method'=>"POST",
                'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
                    "Content-length:".strlen($data)."\r\n" .
                    "\r\n",
                'content' => $data,
            ]
        ];
        $cxContext = stream_context_create($opts);
        return json_decode(file_get_contents("http://localhost:8080/analysis", false, $cxContext));
    }

//    public static function cut($content)
//    {
//        ini_set('memory_limit', '-1');
//        Jieba::init();
//        Finalseg::init();
//        return Jieba::cut($content);
//    }

}